<?php
/** @author lalo */

include_once 'Conexion.php';

class Modulo extends Conexion {
    
    public function registrar ($idCursoTaller, $nombre, $horas) {
        $this->conectar();
        
        $result = $this->insertar("INSERT INTO modulo(moidcursotaller, monombre, mohoras)
                                        VALUES ($idCursoTaller, '$nombre', $horas)", 
                                        "moidmodulo");
        
        $this->desconectar();
        
        if ($result != false) {

            return $this->obtenerPorId($result);
        } else {
            return $result;
        }
    }
    
    public function obtenerPorId ($idModulo) {
        $this->conectar();
        
        $result = $this->consultar("SELECT * FROM modulo WHERE moidmodulo = $idModulo");
        
        $this->desconectar();
        
        return $result[0];
    }

    public function listarModulosPorIdCursoTaller ($idCursoTaller) {
        $this->conectar();
        
        $result = $this->consultar("SELECT * FROM Modulo WHERE moIdCursoTaller = $idCursoTaller ORDER BY moIdModulo");
        
        $this->desconectar();
        
        return $result;
    }
    
    public function listarModulosPorIdGrupos ($idGrupo) {
        $this->conectar();
        
        $result = $this->consultar("SELECT * FROM Modulo JOIN CursoTaller ON (cutaIdCursoTaller = moIdCursoTaller) 
                                                        JOIN Grupo ON (cutaIdCursoTaller = grIdCursoTaller) 
                                                            WHERE grIdGrupo = $idGrupo ORDER BY moIdModulo");
        
        $this->desconectar();
        
        return $result;
    }
    
    public function relacionModuloProfesor ($idGrupo) {
        $this->conectar();
        
        $result = $this->consultar("SELECT * FROM ModuloProfesor 
                                                WHERE moprIdGrupo = $idGrupo ORDER BY moprIdModulo");
        
        $this->desconectar();
        
        return $result;
    }
}

?>